package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.common.PageResult;
import com.itheima.domain.SmsCouponHistory;
import com.itheima.mapper.SmsCouponHistoryMapper;
import com.itheima.service.SmsCouponHistoryService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 优惠券使用、领取历史表 服务实现类
 * </p>
 *
 * @author zhuguo
 * @since 2022-11-10
 */
@DubboService
public class SmsCouponHistoryServiceImpl extends ServiceImpl<SmsCouponHistoryMapper, SmsCouponHistory> implements SmsCouponHistoryService {

    @Autowired
    SmsCouponHistoryMapper smsCouponHistoryMapper;

    @Override
    public PageResult pageByCondition(Integer couponId, String orderSn, Integer pageNum, Integer pageSize, Integer userStatus) {
        Page<SmsCouponHistory> page = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<SmsCouponHistory> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SmsCouponHistory::getCouponId,couponId)
                .eq(orderSn!=null,SmsCouponHistory::getOrderSn,orderSn)
                .eq(userStatus!=null,SmsCouponHistory::getUseStatus,userStatus);
        smsCouponHistoryMapper.selectPage(page,lambdaQueryWrapper);
        return new PageResult(pageNum,pageSize,page.getTotal(),page.getPages(),page.getRecords());
    }
}
